using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using MageDefender.Interfaces;

namespace MageDefender.Scenes
{
    public class StoryScene : Microsoft.Xna.Framework.DrawableGameComponent
    {
        bool startGame;

        public bool StartGame
        {
            get { return startGame; }
            set { startGame = value; }
        }

        int displayStoryNumber = 1;

        public int DisplayStoryNumber
        {
            get { return displayStoryNumber; }
            set { displayStoryNumber = value; }
        }

        Texture2D texStory1;
        Texture2D texStory2;
        SpriteBatch spriteBatch;

        public StoryScene(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            startGame = false;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            texStory1 = this.Game.Content.Load<Texture2D>("Textures\\story");
            texStory2 = this.Game.Content.Load<Texture2D>("Textures\\story2");

            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            base.LoadContent();
        }


        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            IPlayer player = (IPlayer)Game.Services.GetService(typeof(IPlayer));
            GamePadState playerState = GamePad.GetState(player.PlayerIndexSaved);
            KeyboardState keybaord = Keyboard.GetState();

            if (playerState.Buttons.Start == ButtonState.Pressed || keybaord.IsKeyDown(Keys.E))
            {
                startGame = true;
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            switch (displayStoryNumber)
            {
                case 1:
                {
                    spriteBatch.Draw(texStory1, new Rectangle(0, 0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth, Game.GraphicsDevice.PresentationParameters.BackBufferHeight), Color.White);
                    break;
                }
                case 2:
                {
                    spriteBatch.Draw(texStory2, new Rectangle(0, 0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth, Game.GraphicsDevice.PresentationParameters.BackBufferHeight), Color.White);
                    break;
                }
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
